def simple_corutting():
    """Get
    >>> g = simple_corutting()
    >>> g # doctest: +ELLIPSIS
    <generator object simple_corutting at 0x...>
    >>> gr = next(g)
    start it
    >>> gr
    >>> # continue with 42
    >>> g.send(42) # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    StopIteration
    >>> for x in simple_corutting():
    ...   print('x', x)
    ...   pass
    start it
    x None
    continue with None
    >>> g = simple_corutting()
    >>> g.send(None) # 相当于next
    start it
    """
    print("start it")
    x = yield
    print("continue with", x)


def simple_coro2(a):
    """Compute action
    >>> for x in simple_coro2(14):
    ...   print('x', x)
    start a 14
    x 14
    received b None
    x 14
    received c None
    >>> g = simple_coro2(14)
    >>> next(g)
    start a 14
    14
    """
    print("start a", a)
    b = yield a
    print("received b", b)
    c = yield a + (b or 0)
    print("received c", c)


def simple_coro3(a):
    """Compute action
    >>> for x in simple_coro3(14):
    ...   print('x', x)
    start a 14
    x 14
    x None
    received b None
    x 14
    x None
    received c None
    >>> g = simple_coro3(14)
    >>> next(g)
    start a 14
    14
    >>> g.send(None) # 得到 None,没有推动
    >>> g.send(None) # 再推一次
    received b None
    14
    >>> g.send(100) #
    """
    print("start a", a)
    yield a
    b = yield
    print("received b", b)
    yield a + (b or 0)
    c = yield
    print("received c", c)


def end_gen():
    """
    >>> def echo(value=None):
    ...     print("Execution starts when 'next()' is called for the first time.")
    ...     try:
    ...         while True:
    ...             try:
    ...                 value = (yield value)
    ...             except Exception as e:
    ...                 value = e
    ...     except Exception as ee:
    ...         print("what", ee) # 不会进入
    ...         yield ee
    ...     finally:
    ...         print("Don't forget to clean up when 'close()' is called.")
    ...
    >>> generator = echo(1)
    >>> print(next(generator))
    Execution starts when 'next()' is called for the first time.
    1
    >>> print(next(generator))
    None
    >>> print(generator.send(2))
    2
    >>> generator.throw(TypeError, "spam")
    TypeError('spam')
    >>> generator.close()
    Don't forget to clean up when 'close()' is called.
    """


if __name__ == "__main__":
    import doctest

    print("gen 测试开始")
    (ff, tt) = doctest.testmod()
    print("测试结束:统计-失败{},总计{}".format(ff, tt))
    print("√" * tt if tt > 0 and not ff else "无测试" if not ff else "×" * ff)
